Add ostree_repo_pull_default_console_progress_changed()
authorMatthew Barnes <mbarnes@redhat.com>
Thu, 18 Dec 2014 15:06:47 +0000 (10:06 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Fri, 19 Dec 2014 02:31:53 +0000 (21:31 -0500)
Replaces ot_common_pull_progress() in ostree binary, so it can be shared
with rpm-ostree.

Makefile-ostree.am
doc/ostree-sections.txt
src/libostree/ostree-repo.c
src/libostree/ostree-repo.h
src/ostree/ot-admin-builtin-switch.c
src/ostree/ot-admin-builtin-upgrade.c
src/ostree/ot-builtin-pull.c
src/ostree/ot-builtins-common.c [deleted file]
src/ostree/ot-builtins-common.h [deleted file]

index 86ee144e67e6f133593863a83a5e2e2deca75586..dc7e83c75aa3a71b6c53f23a55c344601d5e85a0 100644 (file)
@@ -20,8 +20,6 @@
 bin_PROGRAMS += ostree
 
 ostree_SOURCES = src/ostree/main.c \
-       src/ostree/ot-builtins-common.h \
-       src/ostree/ot-builtins-common.c \
        src/ostree/ot-builtin-admin.c \
        src/ostree/ot-builtins.h \
        src/ostree/ot-builtin-cat.c \
index 535220de58669270ea01ff83ecf351835c50ca43..ceb1fa39e457f09f95554e686a248d40257686b0 100644 (file)
@@ -279,6 +279,7 @@ OstreeRepoPullFlags
 ostree_repo_pull
 ostree_repo_pull_one_dir
 ostree_repo_pull_with_options
+ostree_repo_pull_default_console_progress_changed
 ostree_repo_sign_commit
 ostree_repo_append_gpg_signature
 ostree_repo_verify_commit
index 9d581224fdf1ad7614266a03d1a2aa02201f030c..38471a6b8da64877b56abb1f1ac3fe1f5aeaf257 100644 (file)
@@ -2733,6 +2733,80 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
 
 #endif
 
+/**
+ * ostree_repo_pull_default_console_progress_changed:
+ * @progress: Async progress
+ * @user_data: (allow-none): User data
+ *
+ * Convenient "changed" callback for use with
+ * ostree_async_progress_new_and_connect() when pulling from a remote
+ * repository.
+ *
+ * Depending on the state of the #OstreeAsyncProgress, either displays a
+ * custom status message, or else outstanding fetch progress in bytes/sec,
+ * or else outstanding content or metadata writes to the repository in
+ * number of objects.
+ **/
+void
+ostree_repo_pull_default_console_progress_changed (OstreeAsyncProgress *progress,
+                                                   gpointer             user_data)
+{
+  GSConsole *console = user_data;
+  GString *buf;
+  gs_free char *status = NULL;
+  guint outstanding_fetches;
+  guint outstanding_writes;
+  guint n_scanned_metadata;
+
+  if (!console)
+    return;
+
+  buf = g_string_new ("");
+
+  status = ostree_async_progress_get_status (progress);
+  outstanding_fetches = ostree_async_progress_get_uint (progress, "outstanding-fetches");
+  outstanding_writes = ostree_async_progress_get_uint (progress, "outstanding-writes");
+  n_scanned_metadata = ostree_async_progress_get_uint (progress, "scanned-metadata");
+  if (status)
+    {
+      g_string_append (buf, status);
+    }
+  else if (outstanding_fetches)
+    {
+      guint64 bytes_transferred = ostree_async_progress_get_uint64 (progress, "bytes-transferred");
+      guint fetched = ostree_async_progress_get_uint (progress, "fetched");
+      guint requested = ostree_async_progress_get_uint (progress, "requested");
+      guint64 bytes_sec = (g_get_monotonic_time () - ostree_async_progress_get_uint64 (progress, "start-time")) / G_USEC_PER_SEC;
+      gs_free char *formatted_bytes_transferred =
+        g_format_size_full (bytes_transferred, 0);
+      gs_free char *formatted_bytes_sec = NULL;
+
+      if (!bytes_sec) // Ignore first second
+        formatted_bytes_sec = g_strdup ("-");
+      else
+        {
+          bytes_sec = bytes_transferred / bytes_sec;
+          formatted_bytes_sec = g_format_size (bytes_sec);
+        }
+
+      g_string_append_printf (buf, "Receiving objects: %u%% (%u/%u) %s/s %s",
+                              (guint)((((double)fetched) / requested) * 100),
+                              fetched, requested, formatted_bytes_sec, formatted_bytes_transferred);
+    }
+  else if (outstanding_writes)
+    {
+      g_string_append_printf (buf, "Writing objects: %u", outstanding_writes);
+    }
+  else
+    {
+      g_string_append_printf (buf, "Scanning metadata: %u", n_scanned_metadata);
+    }
+
+  gs_console_begin_status_line (console, buf->str, NULL, NULL);
+
+  g_string_free (buf, TRUE);
+}
+
 /**
  * ostree_repo_append_gpg_signature:
  * @self: Self
index b08c0f5e4685c69a02e8066fb13d89e6a5a422a7..be04aa5be9c78d9702bb99f01a92acae388d6405 100644 (file)
@@ -591,6 +591,9 @@ gboolean ostree_repo_pull_with_options (OstreeRepo             *self,
                                         GCancellable           *cancellable,
                                         GError                **error);
 
+void ostree_repo_pull_default_console_progress_changed (OstreeAsyncProgress *progress,
+                                                        gpointer             user_data);
+
 gboolean ostree_repo_sign_commit (OstreeRepo     *self,
                                   const gchar    *commit_checksum,
                                   const gchar    *key_id,
index 2f6c334344e7ff00c3738d74262e9448ffac7a20..ff9d6e9d58c90b6b0bf2a19be7261ac62bf3b0ff 100644 (file)
@@ -23,7 +23,6 @@
 #include "ot-main.h"
 #include "ot-admin-builtins.h"
 #include "ot-admin-functions.h"
-#include "ot-builtins-common.h"
 #include "ostree.h"
 #include "otutil.h"
 #include "libgsystem.h"
@@ -129,7 +128,7 @@ ot_admin_builtin_switch (int argc, char **argv, GCancellable *cancellable, GErro
     {
       gs_console_begin_status_line (console, "", NULL, NULL);
       in_status_line = TRUE;
-      progress = ostree_async_progress_new_and_connect (ot_common_pull_progress, console);
+      progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, console);
     }
 
   /* Always allow older...there's not going to be a chronological
index 1dff0a5307628afb05eb9641874f9f35aef1ffff..5ccd0b34a2f6eb678cb34570ce926b2820eb304c 100644 (file)
@@ -25,7 +25,6 @@
 #include "ot-main.h"
 #include "ot-admin-builtins.h"
 #include "ot-admin-functions.h"
-#include "ot-builtins-common.h"
 #include "ostree.h"
 #include "otutil.h"
 #include "libgsystem.h"
@@ -84,7 +83,7 @@ ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GErr
     {
       gs_console_begin_status_line (console, "", NULL, NULL);
       in_status_line = TRUE;
-      progress = ostree_async_progress_new_and_connect (ot_common_pull_progress, console);
+      progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, console);
     }
 
   if (opt_allow_downgrade)
index ed013ca840fc752bfacbba33eb2d45690bd257ee..0846605464a0ea3372cbd5bab2cddc3b6106511d 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "ot-main.h"
 #include "ot-builtins.h"
-#include "ot-builtins-common.h"
 #include "ostree.h"
 #include "otutil.h"
 
@@ -97,7 +96,7 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
   if (console)
     {
       gs_console_begin_status_line (console, "", NULL, NULL);
-      progress = ostree_async_progress_new_and_connect (ot_common_pull_progress, console);
+      progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, console);
     }
 
   {
diff --git a/src/ostree/ot-builtins-common.c b/src/ostree/ot-builtins-common.c
deleted file mode 100644 (file)
index 9595ab4..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- *
- * Copyright (C) 2013 Colin Walters <walters@verbum.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "ot-main.h"
-#include "ot-builtins-common.h"
-#include "otutil.h"
-
-void
-ot_common_pull_progress (OstreeAsyncProgress       *progress,
-                         gpointer                   user_data)
-{
-  GSConsole *console = user_data;
-  GString *buf;
-  gs_free char *status = NULL;
-  guint outstanding_fetches;
-  guint outstanding_writes;
-  guint n_scanned_metadata;
-
-  if (!console)
-    return;
-
-  buf = g_string_new ("");
-
-  status = ostree_async_progress_get_status (progress);
-  outstanding_fetches = ostree_async_progress_get_uint (progress, "outstanding-fetches");
-  outstanding_writes = ostree_async_progress_get_uint (progress, "outstanding-writes");
-  n_scanned_metadata = ostree_async_progress_get_uint (progress, "scanned-metadata");
-  if (status)
-    {
-      g_string_append (buf, status);
-    }
-  else if (outstanding_fetches)
-    {
-      guint64 bytes_transferred = ostree_async_progress_get_uint64 (progress, "bytes-transferred");
-      guint fetched = ostree_async_progress_get_uint (progress, "fetched");
-      guint requested = ostree_async_progress_get_uint (progress, "requested");
-      guint64 bytes_sec = (g_get_monotonic_time () - ostree_async_progress_get_uint64 (progress, "start-time")) / G_USEC_PER_SEC;
-      gs_free char *formatted_bytes_transferred =
-        g_format_size_full (bytes_transferred, 0);
-      gs_free char *formatted_bytes_sec = NULL;
-
-      if (!bytes_sec) // Ignore first second
-        formatted_bytes_sec = g_strdup ("-");
-      else
-        {
-          bytes_sec = bytes_transferred / bytes_sec;
-          formatted_bytes_sec = g_format_size (bytes_sec);
-        }
-
-      g_string_append_printf (buf, "Receiving objects: %u%% (%u/%u) %s/s %s",
-                              (guint)((((double)fetched) / requested) * 100),
-                              fetched, requested, formatted_bytes_sec, formatted_bytes_transferred);
-    }
-  else if (outstanding_writes)
-    {
-      g_string_append_printf (buf, "Writing objects: %u", outstanding_writes);
-    }
-  else
-    {
-      g_string_append_printf (buf, "Scanning metadata: %u", n_scanned_metadata);
-    }
-
-  gs_console_begin_status_line (console, buf->str, NULL, NULL);
-  
-  g_string_free (buf, TRUE);
-  
-}
diff --git a/src/ostree/ot-builtins-common.h b/src/ostree/ot-builtins-common.h
deleted file mode 100644 (file)
index deb599a..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- *
- * Copyright (C) 2013 Colin Walters <walters@verbum.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#pragma once
-
-#include <ostree.h>
-
-void
-ot_common_pull_progress (OstreeAsyncProgress       *progress,
-                         gpointer                   user_data);